package data.structure.arithmetic.sort;

import java.lang.reflect.Array;
import java.util.Arrays;

public class Sort {

    public static void main(String[] args) {
        int arr [] ={5,3,6,1,7,4,9,10,8,2};
//        int[] sort = quickSort(arr);
        int[] sort = shellSort(arr);
        System.out.println(Arrays.toString(sort));
    }

    public static int[] selectSort(int [] arr) {
        int index,temp;
        for (int i = 0; i < arr.length; i++) {
            index =i;
            for (int j = i+1; j < arr.length; j++) {
                if (arr[j]<arr[index]) {
                    index = j;
                }
            }
            temp = arr[i];
            arr[i] = arr[index];
            arr[index] = temp;
        }
        return arr;
    }

    public static int[] shellSort(int [] arr) {
        for (int gap = arr.length/2; gap >0; gap/=2) {
            //对每一组进行插入拍排序
            for (int i = gap; i <arr.length; i++) {
                int index = i;
                int temp = arr[index];
                //说明这一组后面的比前面的大,所以开始插入排序
                if (arr[index]<arr[index-gap]) {
                    while (index-gap>=0&&arr[index-gap]>temp) {
                        arr[index] = arr[index-gap];
                        index -= gap;
                    }
                    arr[index] = temp;
                }
            }
        }
        return arr;
    }

    public static int[] quickSort(int [] arr,int left,int right) {

        return arr;
    }


}
